# CMake最低版本要求
cmake_minimum_required(VERSION 3.16)

# 项目信息
project(push-box VERSION 1.0)

# set the output directory for built objects.
# This makes sure that the dynamic library goes into the build directory automatically.
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# 设置 SDL3 的安装路径
set(SDL3_DIR "D:/software/libs/SDL3-3.2.26/x86_64-w64-mingw32")

# 查找 SDL3 包
find_package(SDL3 REQUIRED CONFIG PATHS ${SDL3_DIR})

if(POLICY CMP0025)
    cmake_policy(SET CMP0025 NEW)
endif()

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/$<CONFIGURATION>")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/$<CONFIGURATION>")

# This assumes the SDL source is available in vendored/SDL
# add_subdirectory(vendored/SDL EXCLUDE_FROM_ALL)

# 查找路径下的所有源文件并添加到可执行文件中
# add_executable(push-box src/main.cpp)
file(GLOB_RECURSE SOURCES "src/*.cpp" "src/*.cc")
if(WIN32)
    add_executable(push-box WIN32 ${SOURCES})
    target_compile_options(push-box PRIVATE /source-charset:utf-8 /execution-charset:utf-8)
else()
    add_executable(push-box ${SOURCES})
endif()
target_include_directories(push-box PRIVATE ${PROJECT_SOURCE_DIR}/src)
# include_directories(${PROJECT_SOURCE_DIR})

# Link to the actual SDL3 library.
target_link_libraries(push-box PRIVATE SDL3::SDL3)

file(GLOB RESOURCES "res/*")
add_custom_command(
    OUTPUT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/res
    COMMAND ${CMAKE_COMMAND} -E copy_directory
            ${CMAKE_SOURCE_DIR}/res
            ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/res
    COMMENT "Copying res directory to build directory"
    DEPENDS ${RESOURCES}  # 依赖于 res 目录中的所有文件
)

add_custom_target(copy_res ALL
    DEPENDS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/res
)
add_dependencies(push-box copy_res)

target_compile_features(push-box PRIVATE cxx_std_11)

add_custom_command(TARGET push-box POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy_if_different
    "D:/software/libs/SDL3-3.2.26/x86_64-w64-mingw32/bin/SDL3.dll"
    $<TARGET_FILE_DIR:push-box>
)